layui.use(['form','tree','element','table','laytpl','treeGrid','layer','jquery'],function(){
    var form = layui.form,
        element = layui.element;
    $ = layui.$;
    var layer = parent.layer === undefined ? layui.layer : top.layer;
    var table = layui.table;
    var laytpl = layui.laytpl;
    var layedit = layui.layedit;

    //获取路径参数
    var request = GetRequest();

    //列表数据
    var option = {
        elem: '#tableList',
        url : '/record/invest/query?produceBatchId=' + request.id + '&processId=' + request.processId,
        cellMinWidth : 95,
        page : false,
        height : "full-125",
        limits : [10,15,20,25],
        limit : 15,
        id : "listTable",
        cols : [[
            {field: 'name', title: '投入品', minWidth:100, align:"center"},
            {field: 'weight', title: '使用分量', minWidth:100, align:"center"},
            {field: 'responsiblePerson', title: '负责人', minWidth:100, align:"center"},
            {field: 'remarks', title: '备注', minWidth:100, align:"center"},
            {field: 'investTime', title: '投入时间', align:'center',minWidth:150,sort:true, templet:function(d){
                    //处理时间
                    var date = new Date(d.investTime);
                    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
                }
            },
            {field: 'createDate', title: '记录时间', align:'center',minWidth:150,sort:true, templet:function(d){
                    //处理时间
                    var date = new Date(d.createDate);
                    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
                }
            }
        ]]
    };

    //投入品记录列表
    var tableIns = table.render(option);

    //转成时间线展示
    $(".search_btn").on("click",function(){
        $.get('/record/invest/query?page=0&limit=1000&produceBatchId=' + request.id + '&processId=' + request.processId,function (data) {
            $(".layui-form.layui-border-box.layui-table-view").hide();
            $.each(data.data,function (i,ele) {
                var date = new Date(ele.investTime);
                var dateStr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
                var innerHtml = '<li class="layui-timeline-item">' +
                    '            <i class="layui-icon layui-timeline-axis"></i>' +
                    '            <div class="layui-timeline-content layui-text">' +
                    '                <h3 class="layui-timeline-title">'+ dateStr +'</h3>' +
                    '                <p>投入品：'+ ele.name +'</p>' +
                    '                <p>使用分量：'+ ele.weight +'</p>' +
                    '                <p>负责人：'+ ele.responsiblePerson +'</p>' +
                    '                <p>备注：</p>' +
                    '                <div>'+ ele.remarks +'</div>' +
                    '            </div>' +
                    '        </li>';
                $("#table-timeline").append(innerHtml);
            });
        });
    });


    /**
     * 获取路径中的参数
     * @returns {Object}
     */
    function GetRequest() {
        var url = location.search;         //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

});